package com.jiepu.daily.corejava.advanceed.part7network.day0812;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Description:
 * @author: xinjie
 * @date: 2020/8/12  8:09
 */
public class ChatServer1 {
	public static void main(String[] args) {
		int port = 8888;
		try {
			ServerSocket ss = new ServerSocket(port);
			System.out.println("Server started. " + port);
			System.out.println("wait a Client ....");
			// 等待 接受client对象  Client 创建一个 Socket对象。
			Socket socket = ss.accept();
			System.out.println("一台client 已连接");

			//
			InputStream is = socket.getInputStream();
		/*	int i =-1;
			while((i=is.read()) != -1){
				System.out.println((char)i);
			}*/
			int msgLen = 13;
			for (int i = 0; i < msgLen; i++) {
				System.out.println((char) is.read());
			}

			/*int i = -1;
			String len = "";
			while (((char) (i = is.read()) != '|')) {
				len += (char) i;
			}
			for (int i = 0; i < Integer.parseInt(len); i++) {
				System.out.println((char) is.read());
			}*/


		} catch (IOException e) {
			e.printStackTrace();
		}

	} // main

}
